// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/*!
 * @file char_sequenceTypeObjectSupport.cxx
 * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file
 *
 * This file was generated by the tool fastddsgen.
 */

#include "char_sequenceTypeObjectSupport.hpp"

#include <mutex>
#include <string>

#include <fastcdr/xcdr/external.hpp>
#include <fastcdr/xcdr/optional.hpp>
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/log/Log.hpp>
#include <fastdds/dds/xtypes/common.hpp>
#include <fastdds/dds/xtypes/type_representation/ITypeObjectRegistry.hpp>
#include <fastdds/dds/xtypes/type_representation/TypeObject.hpp>
#include <fastdds/dds/xtypes/type_representation/TypeObjectUtils.hpp>

#include "char_sequence.hpp"


using namespace eprosima::fastdds::dds::xtypes;

// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method
void register_char_sequence_type_identifier(
        TypeIdentifierPair& type_ids_char_sequence)
{

    ReturnCode_t return_code_char_sequence {eprosima::fastdds::dds::RETCODE_OK};
    return_code_char_sequence =
        eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
        "char_sequence", type_ids_char_sequence);
    if (eprosima::fastdds::dds::RETCODE_OK != return_code_char_sequence)
    {
        StructTypeFlag struct_flags_char_sequence = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE,
                false, false);
        QualifiedTypeName type_name_char_sequence = "char_sequence";
        eprosima::fastcdr::optional<AppliedBuiltinTypeAnnotations> type_ann_builtin_char_sequence;
        eprosima::fastcdr::optional<AppliedAnnotationSeq> ann_custom_char_sequence;
        CompleteTypeDetail detail_char_sequence = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_char_sequence, ann_custom_char_sequence, type_name_char_sequence.to_string());
        CompleteStructHeader header_char_sequence;
        header_char_sequence = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_char_sequence);
        CompleteStructMemberSeq member_seq_char_sequence;
        {
            TypeIdentifierPair type_ids_chars;
            ReturnCode_t return_code_chars {eprosima::fastdds::dds::RETCODE_OK};
            return_code_chars =
                eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                "anonymous_sequence_char_unbounded", type_ids_chars);

            if (eprosima::fastdds::dds::RETCODE_OK != return_code_chars)
            {
                return_code_chars =
                    eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                    "_char", type_ids_chars);

                if (eprosima::fastdds::dds::RETCODE_OK != return_code_chars)
                {
                    EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                            "Sequence element TypeIdentifier unknown to TypeObjectRegistry.");
                    return;
                }
                bool element_identifier_anonymous_sequence_char_unbounded_ec {false};
                TypeIdentifier* element_identifier_anonymous_sequence_char_unbounded {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_chars, element_identifier_anonymous_sequence_char_unbounded_ec))};
                if (!element_identifier_anonymous_sequence_char_unbounded_ec)
                {
                    EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Sequence element TypeIdentifier inconsistent.");
                    return;
                }
                EquivalenceKind equiv_kind_anonymous_sequence_char_unbounded = EK_COMPLETE;
                if (TK_NONE == type_ids_chars.type_identifier2()._d())
                {
                    equiv_kind_anonymous_sequence_char_unbounded = EK_BOTH;
                }
                CollectionElementFlag element_flags_anonymous_sequence_char_unbounded = 0;
                PlainCollectionHeader header_anonymous_sequence_char_unbounded = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_sequence_char_unbounded, element_flags_anonymous_sequence_char_unbounded);
                {
                    SBound bound = 0;
                    PlainSequenceSElemDefn seq_sdefn = TypeObjectUtils::build_plain_sequence_s_elem_defn(header_anonymous_sequence_char_unbounded, bound,
                                eprosima::fastcdr::external<TypeIdentifier>(element_identifier_anonymous_sequence_char_unbounded));
                    if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
                            TypeObjectUtils::build_and_register_s_sequence_type_identifier(seq_sdefn, "anonymous_sequence_char_unbounded", type_ids_chars))
                    {
                        EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                            "anonymous_sequence_char_unbounded already registered in TypeObjectRegistry for a different type.");
                    }
                }
            }
            StructMemberFlag member_flags_chars = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
                    false, false, false, false);
            MemberId member_id_chars = 0x00000000;
            bool common_chars_ec {false};
            CommonStructMember common_chars {TypeObjectUtils::build_common_struct_member(member_id_chars, member_flags_chars, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_chars, common_chars_ec))};
            if (!common_chars_ec)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure chars member TypeIdentifier inconsistent.");
                return;
            }
            MemberName name_chars = "chars";
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_chars;
            ann_custom_char_sequence.reset();
            CompleteMemberDetail detail_chars = TypeObjectUtils::build_complete_member_detail(name_chars, member_ann_builtin_chars, ann_custom_char_sequence);
            CompleteStructMember member_chars = TypeObjectUtils::build_complete_struct_member(common_chars, detail_chars);
            TypeObjectUtils::add_complete_struct_member(member_seq_char_sequence, member_chars);
        }
        CompleteStructType struct_type_char_sequence = TypeObjectUtils::build_complete_struct_type(struct_flags_char_sequence, header_char_sequence, member_seq_char_sequence);
        if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
                TypeObjectUtils::build_and_register_struct_type_object(struct_type_char_sequence, type_name_char_sequence.to_string(), type_ids_char_sequence))
        {
            EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                    "char_sequence already registered in TypeObjectRegistry for a different type.");
        }
    }
}

